home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Floppyshop 2
/
Floppyshop - 2.zip
/
Floppyshop - 2.iso
/
art&graf.ix
/
art-0039
/
source
/
degascon.mod
< prev
next >
Wrap
Text File
|
1997-04-16
|
26KB
|
772 lines
MODULE DegasConvert;
(*--------------------------------------------------------------------*)
(* *)
(* The program was completely re-written in August 1987 to use *)
(* modules more effectively and use the colour palette information *)
(* when converting pictures to hi-resolution. *)
(* *)
(* This module is the high-level control logic for the program. *)
(* This module will respond to all messages from GEM and pass *)
(* control to the appropriate routines. It will look after the *)
(* menu. It will also deal with initialisation and termination. *)
(* *)
(* When Ver Who Why *)
(* -------- ---- --- --------------------------- *)
(* 17/ 9/89 2.04 LGM Change number of blocks allocated depending *)
(* on free memory. *)
(* Reset palette frequently. *)
(* *)
(* 25/ 8/89 LGM : Added Image selection from menu. *)
(* *)
(* Version 2.01 November 1988 L.G. Miller *)
(* :- '.IMG' Processing. *)
(* *)
(* Version 2.00 July 1988 L.G. Miller *)
(* :- split up menu processing. *)
(* add new options. *)
(* add sub image selection *)
(* April 1988 L.G. Miller *)
(* April 1987 L.G. Miller *)
(* *)
(* Medium res bug fixed in June 1987 L.G. Miller *)
(*--------------------------------------------------------------------*)
(* IMPORT Trace; *)
FROM DCGlobal IMPORT LowRes, MedRes, HiRes,
HiResMaxX, HiResMaxY,
PrintPalette,
PrinterTypes,
PictureImage,
PrintImage,
DegasPicture,
BITSPERWORD,
TheWindow;
FROM DCPrint IMPORT SetPrinterToUse,
PrintHiResPicture;
FROM DCScreen IMPORT DisplayPicture;
FROM DCDAbout IMPORT DoAboutDialog;
FROM DCDPalette IMPORT DoPaletteDialog,
DoPixelDialog;
FROM DCDPrintImage IMPORT DoImageDialog;
FROM DCSelImg IMPORT DoMedResSelectImage,
DoHiResSelectImage;
FROM DCConvrt IMPORT ConvertDegasToHiRes,
ClearPicture,
SetLowResDefaultPrintPalette,
SetMedResDefaultPrintPalette;
FROM DCCnvImg IMPORT ConvertToImage;
FROM DCFileIO IMPORT LoadDegasFile,
SaveDegasFile,
SaveImageFile;
FROM SYSTEM IMPORT ADDRESS, ADR;
FROM Storage IMPORT ALLOCATE, DEALLOCATE, Cleanup, Available,
MaxBlocks, LargestBlock;
FROM Bios IMPORT setColor;
FROM GemDos IMPORT Malloc;
FROM Strings IMPORT String,
Assign,
Concat;
FROM Resource IMPORT Objects,
rsrc_load,
rsrc_free,
rsrc_gaddr;
IMPORT Object;
FROM MenuLib IMPORT menu_bar,
menu_ienable,
menu_tnormal,
menu_icheck;
IMPORT Forms;
IMPORT Graphics;
IMPORT Event;
IMPORT Window;
(* INCLUDE FOR ManyWindows ; *)
FROM Window IMPORT
Components,
(* =(AESWNU1,AESWNU2,AESWNU3,AESWNU4, (*top 4 bits unused *)
HSLIDE, (*horizontal slider*)
RTARROW, (*right arrow*)
LFARROW, (*left arrow*)
VSLIDE, (*vertical slider*)
DNARROW, (*down arrow*)
UPARROW, (*up arrow*)
RESIZE, (*re-size box*)
INFO, (*information line*)
MOVE, (*move box*)
FULL, (*full box*)
CLOSE, (*close box*)
NAME); (*title bar with name*) *)
ComponentSet;
FROM ManyWindows IMPORT
XYWHRect,
CornersRect,
WindowStates, (* = ( open, full, topped ); *)
WindowSSet, (* = SET OF WindowStates; *)
WindowPtr, (* = POINTER TO AWindow; *)
AWindow, (* = RECORD
Handle : INTEGER; (* The AES window handle *)
State : WindowSSet;
Outer,
Workarea,
PrevSize : WindowCoordinate;
Components : ComponentSet;
Font : FontData;
Title : String;
END; (* Window *)
VAR *)
AESApplId,
VDIHandle,
ScreenResolution,
ShowAlert,
StartApplication,
CreateAWindow,
SetAWindowTitle,
OpenAWindow,
ClearAWindow,
CloseAWindow,
DeleteAWindow,
TerminateApplication,
(* various conversion / translation utilities *)
ToXYWHRect,
ToCornersRect,
QueryIntersect,
GetWindowHandle,
GetWindowPtr,
BeginScreenUpdate,
EndScreenUpdate,
ShowMouse,
HideMouse;
(* END ManyWindows. *)
(*----------------------------------------------------------------------*)
(* Resource file object numbers *)
(*----------------------------------------------------------------------*)
FROM Dcrsc IMPORT menu,
deskmenu, mabout,
filemenu,
mfload, mfsave, mfimage,
mfquit,
prntmenu,
mpprint, mpsize,
picmenu,
mpicpat, mpiccnv,
imgmenu,
mimgsel,
prtrmenu,
mpmx80, mpfx80, mplq80;
(*----------------------------------------------------------------------*)
(* -------------------- END OF IMPORTS -------------------------------- *)
(*----------------------------------------------------------------------*)
(*----------------------------------------------------------------------*)
(* G L O B A L C O N S T A N T S *)
(*----------------------------------------------------------------------*)
CONST
CVersionString = 'Version 2.04 September 1989';
CResourceFilename = 'DCRSC.RSC';
HourGlass = 2;
Arrow = 0;
(*----------------------------------------------------------------------*)
(* > > > G L O B A L V A R I A B L E S < < < *)
(*----------------------------------------------------------------------*)
VAR
TheInPicture,
TheOutPicture : DegasPicture;
ThePrintPalette : PrintPalette;
ThePictureImage : PictureImage;
ThePrintImage : PrintImage;
FileLoaded : BOOLEAN;
MenuTreePtr : ADDRESS;
ScreenPalette : ARRAY [ 0 .. 15 ] OF INTEGER;
PictureFilename : String; (* used for window title *)
DummyWord1 : CARDINAL; (* force word boundary *)
(* dummy variables - saves having to keep declaring 'em *)
dumc : CARDINAL;
dumi : INTEGER;
dumf : BOOLEAN;
dumlc : LONGCARD;
PROCEDURE SetPalette;
BEGIN
IF ScreenResolution = MedRes THEN
dumc := setColor(777H,0); (* white *)
dumc := setColor(555H,1); (* grey *)
dumc := setColor(333H,2); (* grey *)
dumc := setColor(000H,3); (* black *)
END;
END SetPalette;
(*----------------------------------------------------------------------*)
(* Process Left Button Event *)
(*----------------------------------------------------------------------*)
PROCEDURE HandleButtonEvent ( x, y, button : CARDINAL );
BEGIN
IF ( y <= TheWindow^.Workarea.Y ) THEN
RETURN
END;
IF FileLoaded THEN
IF TheInPicture.resolution # HiRes THEN
DoPixelDialog ( TheInPicture,
x, y, ScreenResolution,
ThePrintPalette );
ELSE
dumi := ShowAlert('Hi-res pic!',1,1);
END;
ELSE
dumi := ShowAlert('NO Picture loaded',1,1);
END;
END HandleButtonEvent;
(*----------------------------------------------------------------------*)
(* Process Escape Key Event - start selection of sub image. *)
(* Uses Global Variables! *)
(* Set Print Image to same size as picture image, i.e. no scaling *)
(*----------------------------------------------------------------------*)
PROCEDURE SelectImage;
VAR pi : PictureImage;
BEGIN
IF NOT FileLoaded THEN
dumi := ShowAlert('NO Picture loaded',1,1);
RETURN
END;
pi := ThePictureImage;
(* remove everything from the screen *)
dumc := menu_bar( MenuTreePtr, FALSE );
CloseAWindow(TheWindow);
IF ScreenResolution = MedRes THEN
DoMedResSelectImage( ThePictureImage,
TheOutPicture.HiResPicture );
ELSE
DoHiResSelectImage( ThePictureImage,
TheOutPicture.HiResPicture );
END;
IF ( pi.StartX # ThePictureImage.StartX )
OR ( pi.StartY # ThePictureImage.StartY )
OR ( pi.Width # ThePictureImage.Width )
OR ( pi.Height # ThePictureImage.Height ) THEN
ThePrintImage.Width := ThePictureImage.Width;
ThePrintImage.Height := ThePictureImage.Height;
END;
(* reshow everything *)
dumc := menu_bar( MenuTreePtr, TRUE );
OpenAWindow(TheWindow);
ClearAWindow(TheWindow);
DisplayPicture( TheOutPicture.HiResPicture);
END SelectImage;
(*----------------------------------------------------------------------*)
(* Process Escape Key Event - start selection of sub image. *)
(* Uses Global Variables! *)
(* Set Print Image to same size as picture image, i.e. no scaling *)
(*----------------------------------------------------------------------*)
PROCEDURE HandleEscKeyEvent;
BEGIN
IF NOT FileLoaded THEN
dumi := ShowAlert('NO Picture loaded',1,1);
RETURN
ELSE
SelectImage;
END;
END HandleEscKeyEvent;
(*----------------------------------------------------------------------*)
(* Load a picture file. *)
(*----------------------------------------------------------------------*)
PROCEDURE ProcessLoadRequest;
BEGIN
IF LoadDegasFile( TheInPicture,
PictureFilename ) THEN
SetPalette;
FileLoaded := TRUE;
SetAWindowTitle( TheWindow, PictureFilename );
IF TheInPicture.resolution = LowRes THEN
SetLowResDefaultPrintPalette(TheInPicture.LowPalette,
ThePrintPalette );
ELSE
SetMedResDefaultPrintPalette( TheInPicture.MedPalette,
ThePrintPalette );
END;
WITH ThePictureImage DO
StartX := 0;
StartY := 0;
Width := HiResMaxX + 1;
Height := HiResMaxY + 1;
END; (* with *)
WITH ThePrintImage DO
StartCharX := 5;
StartCharY := 5;
Width := HiResMaxX + 1;
Height := HiResMaxY + 1;
QueryLandscapePrint := FALSE;
END; (* with *)
dumc := Graphics.graf_mouse(HourGlass, NIL);
ShowMouse;
ConvertDegasToHiRes ( TheInPicture,
TheOutPicture,
ThePrintPalette );
dumc := Graphics.graf_mouse(Arrow,NIL);
HideMouse;
END; (* if *)
DisplayPicture( TheOutPicture.HiResPicture);
END ProcessLoadRequest;
(*----------------------------------------------------------------------*)
(* Change current print palette if changed, convert picture *)
(*----------------------------------------------------------------------*)
PROCEDURE ModifyPrintPalette ( VAR inpicture,
outpicture : DegasPicture;
VAR pp : PrintPalette );
VAR tempp : PrintPalette;
BEGIN
tempp := pp;
IF DoPaletteDialog( tempp, inpicture.resolution ) THEN
pp := tempp;
dumc := Graphics.graf_mouse(HourGlass, NIL);
ConvertDegasToHiRes( inpicture, outpicture, pp );
dumc := Graphics.graf_mouse(Arrow, NIL);
END;
END ModifyPrintPalette;
(*----------------------------------------------------------------------*)
(* Convert portion of picture to IMG format & save it *)
(*----------------------------------------------------------------------*)
PROCEDURE SaveImage( VAR OutPic : DegasPicture;
VAR PicImage : PictureImage );
CONST CIMGBufferSize = LONGCARD(40000);
VAR outlen : CARDINAL;
IMGBuffer : ADDRESS;
BEGIN
IF (PicImage.Width = 0)
OR (PicImage.Height = 0) THEN
dumi := ShowAlert('NO Image Selected',1,1);
RETURN;
END;
IF NOT Available(CIMGBufferSize) THEN
dumi := ShowAlert('NO Room for image buffer',1,1);
RETURN;
END;
ALLOCATE(IMGBuffer, CIMGBufferSize);
ConvertToImage( PicImage,
OutPic.HiResPicture,
outlen,
IMGBuffer );
IF NOT SaveImageFile( outlen, IMGBuffer ) THEN END;
DEALLOCATE(IMGBuffer, CIMGBufferSize);
END SaveImage;
(*----------------------------------------------------------------------*)
(* Tell print module which printer is connected. *)
(*----------------------------------------------------------------------*)
PROCEDURE ChangePrinterSelected ( menuitem : INTEGER ) ;
CONST check = TRUE;
nocheck = FALSE;
BEGIN
dumc := menu_icheck(MenuTreePtr, mpmx80, nocheck);
dumc := menu_icheck(MenuTreePtr ,mpfx80, nocheck);
dumc := menu_icheck(MenuTreePtr ,mplq80, nocheck);
CASE menuitem OF
mpmx80 : dumc := menu_icheck(MenuTreePtr, mpmx80, check);
SetPrinterToUse( EpsonMX80 ); |
mpfx80 : dumc := menu_icheck( MenuTreePtr, mpfx80, check );
SetPrinterToUse( EpsonFX80 ); |
mplq80 : dumc := menu_icheck( MenuTreePtr, mplq80, check );
SetPrinterToUse( EpsonLQ80 ); |
END;
END ChangePrinterSelected ;
(*----------------------------------------------------------------------*)
(* Each sub-menu has its own procedure *)
(*----------------------------------------------------------------------*)
PROCEDURE ProcessFileMenu ( Item : INTEGER; VAR terminate : BOOLEAN );
BEGIN
CASE Item OF
mfload : ProcessLoadRequest |
mfsave : IF FileLoaded THEN
IF SaveDegasFile(TheOutPicture) THEN
END; (* if *)
ELSE
dumi := ShowAlert('NO Picture loaded',1,1);
END; |
mfimage : SaveImage( TheOutPicture,
ThePictureImage ); |
mfquit : terminate := TRUE; |
ELSE
END ;
END ProcessFileMenu;
PROCEDURE ProcessPrintMenu ( Item : INTEGER );
BEGIN
CASE Item OF
mpprint : IF FileLoaded THEN
dumc := Graphics.graf_mouse(HourGlass, NIL);
PrintHiResPicture( ThePictureImage,
ThePrintImage,
TheOutPicture.HiResPicture );
dumc := Graphics.graf_mouse(Arrow, NIL);
ELSE
dumi := ShowAlert('NO Picture loaded',1,1);
END; |
mpsize : IF FileLoaded THEN
DoImageDialog( ThePictureImage,
ThePrintImage );
DisplayPicture( TheOutPicture.HiResPicture );
ELSE
dumi := ShowAlert('NO Picture loaded',1,1);
END; |
ELSE
END;
END ProcessPrintMenu;
PROCEDURE ProcessPictureMenu ( Item : INTEGER );
BEGIN
CASE Item OF
mpicpat : IF FileLoaded THEN
SetPalette;
IF TheInPicture.resolution # HiRes THEN
ModifyPrintPalette( TheInPicture,
TheOutPicture,
ThePrintPalette);
DisplayPicture( TheOutPicture.HiResPicture );
ELSE
dumi := ShowAlert('Hi-res picture, no palette',1,1);
END;
ELSE
dumi := ShowAlert('NO Picture loaded',1,1);
END; |
mpiccnv : IF FileLoaded THEN
dumc := Graphics.graf_mouse(HourGlass, NIL);
ConvertDegasToHiRes( TheInPicture,
TheOutPicture,
ThePrintPalette );
dumc := Graphics.graf_mouse(Arrow, NIL);
ELSE
dumi := ShowAlert('NO Picture loaded',1,1);
END; |
ELSE
END; (* case *)
END ProcessPictureMenu;
PROCEDURE ProcessImageMenu ( Item : INTEGER );
BEGIN
CASE Item OF
mimgsel : IF FileLoaded THEN
SelectImage;
ELSE
dumi := ShowAlert('Hi-res picture, no palette',1,1);
END;
ELSE
END; (* case *)
END ProcessImageMenu;
(*----------------------------------------------------------------------*)
(* Which menu item was selected... and action it... *)
(*----------------------------------------------------------------------*)
PROCEDURE SelectMenu( Menu, Item : INTEGER; VAR terminate : BOOLEAN );
BEGIN
CASE Menu OF
deskmenu : IF Item = mabout THEN
DoAboutDialog(CVersionString) ;
DisplayPicture( TheOutPicture.HiResPicture );
ELSE
END;
dumc := menu_tnormal(MenuTreePtr, deskmenu, TRUE); |
filemenu : ProcessFileMenu( Item, terminate ) ;
dumc := menu_tnormal(MenuTreePtr, filemenu, TRUE); |
prntmenu : ProcessPrintMenu( Item );
dumc := menu_tnormal(MenuTreePtr, prntmenu, TRUE); |
picmenu : ProcessPictureMenu( Item );
dumc := menu_tnormal(MenuTreePtr, picmenu, TRUE); |
imgmenu : ProcessImageMenu( Item );
dumc := menu_tnormal(MenuTreePtr, imgmenu, TRUE); |
prtrmenu : ChangePrinterSelected( Item );
dumc := menu_tnormal(MenuTreePtr, prtrmenu, TRUE); |
ELSE
END ;
END SelectMenu ;
(* ------------------------------------------------------------------- *)
(* This is the routine which decides what to do in response to a *)
(* message from GEM. It is the main loop of the program. *)
(* ------------------------------------------------------------------- *)
PROCEDURE HandleEvents ; (* based on GEMDEM *)
(* Handle resource events *)
CONST
CMenuSelected = 10;
CWindowClosed = 22;
CWindowRedraw = 20;
CBeginUpdate = 1;
CEndUpdate = 0;
CKeyEvent = 1;
CEscKey = CARDINAL(011BH);
CButtonEvent = 2;
CMessageEvent = 16;
CEventTypes = CButtonEvent + CMessageEvent + CKeyEvent;
CNumClicks = 1;
CLeftButton = 1;
CButtonDown = 1;
VAR
quit : BOOLEAN;
result : INTEGER ;
pipeBuff : Event.Message ;
evres : Event.EventSet;
WhichEvent : INTEGER;
MoX, MoY, MoButton, MokState, KReturn, BReturn : CARDINAL;
BEGIN
quit := FALSE;
ShowMouse;
LOOP (* do until window closed *)
evres := Event.evnt_multi
( Event.EventSet(CEventTypes), CNumClicks,
CLeftButton,
CButtonDown,
FALSE, 0, 0, 0, 0,
FALSE, 0, 0, 0, 0,
pipeBuff,
LONGCARD(0),
MoX, MoY, MoButton, MokState,
KReturn, BReturn );
WhichEvent := INTEGER(evres);
dumc := Window.wind_update(CBeginUpdate); (* stop anymore messages *)
IF ( WhichEvent = CButtonEvent ) THEN
HandleButtonEvent( MoX, MoY, MoButton );
ELSIF ( WhichEvent = CKeyEvent )
AND ( KReturn = CEscKey ) THEN
HandleEscKeyEvent;
ELSE
CASE CARDINAL(pipeBuff.MessageType) OF (* message type *)
CMenuSelected : SelectMenu( pipeBuff.Message[0],
pipeBuff.Message[1],
quit);
IF quit THEN EXIT END; |
CWindowClosed : EXIT |
CWindowRedraw :
SetPalette;
DisplayPicture( TheOutPicture.HiResPicture );
|
ELSE
END; (* case *)
END; (* if *)
dumc := Window.wind_update(CEndUpdate); (* let user select other things *)
END; (* loop *) ;
dumc := Window.wind_update(CEndUpdate); (* let user select other things *)
END HandleEvents ;
(*----------------------------------------------------------------------*)
(* Save the screen palette as we will be changing it... *)
(*----------------------------------------------------------------------*)
PROCEDURE SaveScreenPalette;
CONST MinusOne = INTEGER(-1);
VAR i : CARDINAL;
BEGIN
FOR i := 0 TO 15 DO ScreenPalette[i] :=
setColor(CARDINAL(MinusOne), i); END;
END SaveScreenPalette;
(*----------------------------------------------------------------------*)
(* Restore screen palette before exiting, user will like that... *)
(*----------------------------------------------------------------------*)
PROCEDURE RestoreScreenPalette;
VAR i,j : CARDINAL;
BEGIN
FOR i := 0 TO 15 DO j := setColor(ScreenPalette[i],i); END;
END RestoreScreenPalette;
(* ----------------------------------------------------------------- *)
(* Load resource file *)
(* ----------------------------------------------------------------- *)
PROCEDURE InitResource() : BOOLEAN ; (* get resource and show menu *)
CONST
NoResourceMsg = 'Cannot find resource file |';
VAR
s : String;
BEGIN
dumc := rsrc_load(CResourceFilename);
IF ( dumc = 0 ) THEN
Concat(NoResourceMsg,CResourceFilename,s);
dumi := ShowAlert(s,1,1);
RETURN(FALSE);
END;
dumc := rsrc_gaddr( tree , menu, MenuTreePtr);
dumc := menu_bar( MenuTreePtr, TRUE );
RETURN(TRUE);
END InitResource;
(*----------------------------------------------------------------------*)
(* Initialisation part of module, this runs the program... *)
(*----------------------------------------------------------------------*)
BEGIN
LargestBlock := LONGCARD(50000);
MaxBlocks := SHORT( Malloc(LONGCARD(-1)) DIV LargestBlock );
SaveScreenPalette;
SetPalette;
SetPrinterToUse(EpsonLQ80);
ClearPicture ( TheOutPicture);
FileLoaded := FALSE;
ThePictureImage.Width := 0;
ThePictureImage.Height := 0;
StartApplication; (* sign on to GEM, open Virtual WS etc. *)
IF NOT InitResource() THEN HALT END;
TheWindow := CreateAWindow(ComponentSet{NAME,CLOSE});
SetAWindowTitle(TheWindow, 'No Picture Loaded');
OpenAWindow(TheWindow);
ClearAWindow(TheWindow);
dumc := Graphics.graf_mouse(Arrow,NIL) ; (* put pointing mouse *)
IF ScreenResolution = LowRes THEN
dumi := ShowAlert('Please Use MEDIUM Resolution',1,1)
ELSE
ProcessLoadRequest;
HandleEvents (* stay there until 'quit' message *)
END;
CloseAWindow(TheWindow);
DeleteAWindow(TheWindow);
dumc := menu_bar(MenuTreePtr, FALSE); (* show original menu *)
dumc := rsrc_free();
RestoreScreenPalette;
TerminateApplication; (* sign off from GEM *)
Cleanup;
END DegasConvert.